import cn.hxz.mapper.TeacherMapper;
import cn.hxz.pojo.Teacher;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class SpringMybatis {

    @Test
    public void test() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        TeacherMapper mapper = ctx.getBean(TeacherMapper.class);
        int id = 2;
        //单条查询
        Teacher teacher = mapper.selectOne(id);
        System.out.println(teacher);
        //新增
        mapper.insert(teacher);
        System.out.println("id=" + teacher.getId());
        //多条
        List<Teacher> teacherList = mapper.selectAll("", 1, 10);
        System.out.println(teacherList);

        //更新
        teacher.setName("刘老师");
        mapper.update(teacher);
        //删除
        mapper.delete(teacher.getId());

        List<Teacher> teachers = mapper.selectAll("", 1, 10);
        System.out.println(teachers);
    }
}
